package com.itheima.reggie;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author 程达
 * @PackageName:com.itheima.reggie
 * @ClassName:ReggieApplication
 * @Description:
 * @date 2022/5/22 9:52
 **/
@Slf4j //是用做日志输出的  	是lombok中提供的注解, 用来通过slf4j记录日志。
@SpringBootApplication//是Spring Boot项目的核心注解，目的是开启自动配置 程序入口，启动引导类
@ServletComponentScan//这个注解是用来扫描子包中关于web 3大组件用的扫描过滤器的  Servlet,Filter,Listener
@EnableTransactionManagement //开启对事物管理的支持
//Service层方法上加的注解@Transactional要想生效，需要在引导类上加上注解 @EnableTransactionManagement， 开启对事务的支持。
@EnableCaching//5.开启spring对缓存注解的支持
public class ReggieApplication {
    public static void main(String[] args) {
        SpringApplication.run(ReggieApplication.class,args);
        log.info("[项目启动成功...]");
    }
    //在配置类中直接返回一个Jackson2ObjectMapperBuilderCustomizer的实例即可,
    // 解决long类型丢失后两位精度直接转化成字符串交互WebMvcConfig中也需要配置重写方法extendMessageConverters方法：
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        Jackson2ObjectMapperBuilderCustomizer customizer = jacksonObjectMapperBuilder ->
                jacksonObjectMapperBuilder
                        .serializerByType(Long.class, ToStringSerializer.instance)
                        .serializerByType(Long.TYPE, ToStringSerializer.instance);
        return customizer;
    }
}
